<template>
  <div class="home">
    <div class="logo-box"></div>
    <div class="search-box">
      <input v-model="words" type="text" />
      <button @click="toSearch">搜索一下</button>
    </div>
    <div class="hot-link">
      热门搜索：
      <!-- 
        query 传参:查询字符串传参
        1. 传递: 路径?参数名=参数值&参数名=参数值
        2. 目标组件中接收参数:$route.query.参数名
         -->
      <!--   <router-link to="/search?words=黑马程序员">黑马程序员</router-link>
      <router-link to="/search?words=前端培训">前端培训</router-link>
      <router-link to="/search?words=如何成为前端大牛">如何成为前端大牛</router-link> -->

      <!-- 动态路由传参 -->
      <!-- 1.在router/index.js 配置动态路由参数, /search/:参数名 -->
      <!-- 2 传递:/search/参数值 -->
      <!-- 3.在目标组件中接收参数:$route.params.参数名 -->

      <router-link to="/search/黑马程序员">黑马程序员</router-link>
      <router-link to="/search/前端培训">前端培训</router-link>
      <router-link to="/search/如何成为前端大牛">如何成为前端大牛</router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: "FindMusic",
  data() {
    return {
      words: "",
    };
  },
  methods: {
    toSearch() {
      //使用js进行路由跳转
      // this.$router.push('路径') 简单写法
      // this.$router.push("/search");
      // this.$router.push({
      //   name: "search",
      // });
      //1.1 path +query 传参
      // this.$router.push("路径?参数名=参数值")
      // 官方的 api
      // this.$router.push({
      //   path: "/search",
      //   query: {
      //     words:this.words
      //   }
      // });
      // this.$router.push(`/search/${this.words}`)  //用params 接收参数

      this.$router.push({
        name: "search",
        params: {
          words: this.words,
        },
      });
    },
  },
};
</script>

<style>
.logo-box {
  height: 150px;
  background: url("@/assets/logo.jpeg") no-repeat center;
}
.search-box {
  display: flex;
  justify-content: center;
}
.search-box input {
  width: 400px;
  height: 30px;
  line-height: 30px;
  border: 2px solid #c4c7ce;
  border-radius: 4px 0 0 4px;
  outline: none;
}
.search-box input:focus {
  border: 2px solid #ad2a26;
}
.search-box button {
  width: 100px;
  height: 36px;
  border: none;
  background-color: #ad2a26;
  color: #fff;
  position: relative;
  left: -2px;
  border-radius: 0 4px 4px 0;
}
.hot-link {
  width: 508px;
  height: 60px;
  line-height: 60px;
  margin: 0 auto;
}
.hot-link a {
  margin: 0 5px;
}
</style>